#include <vector>
using namespace std;
int numSquares(int n) {
  vector<int> dp(n + 1, n + 1);
  dp[0] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 1; j <= 100; ++j) {
      if (i - j * j >= 0) {
        dp[i] = min(dp[i], dp[i - j * j] + 1);
      } else {
        break;
      }
    }
  }
  return dp[n];
}